package com.hoopchina.util.json;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

import com.hoopchina.meta.NewsItem;


public class Json2Locallist {
	public static List<NewsItem>  getLocalList(String jsonStr) throws Exception{
		List<NewsItem> items=null;
		JSONObject baseObject=new JSONObject(jsonStr);
		//JSONArray array=baseObject.getJSONArray("entry");
		JSONArray array=baseObject.optJSONArray("entry");
		int len=array.length();
		for (int i = 0; i < len; i++) {
			if (items==null) {
				items=new ArrayList<NewsItem>();
			}
			NewsItem temItem=new NewsItem();
			JSONObject object=array.getJSONObject(i);
			temItem.setTitle(object.optString("title", ""));
			temItem.setUrl(object.optString("url", ""));
			//urlEnc
			temItem.setAuthor(object.optString("author", ""));
			temItem.setAbs(object.optString("abs", ""));
			temItem.setTime(object.optString("time", ""));
			temItem.setImgUrl(object.optString("imgUrl", ""));
			items.add(temItem);
			temItem=null;
		}
		return items;
	}
}
